package cn.sczhyt.modules.app.controller;

import cn.sczhyt.modules.app.annotation.Login;
import cn.sczhyt.modules.app.annotation.LoginUser;
import cn.sczhyt.modules.app.entity.UserEntity;
import cn.sczhyt.modules.szhy.entity.MeetingEntity;
import cn.sczhyt.modules.szhy.entity.MeetingUserEntity;
import cn.sczhyt.modules.szhy.service.MeetingService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.sczhyt.modules.szhy.entity.MeetingSignInEntity;
import cn.sczhyt.modules.szhy.service.MeetingSignInService;
import cn.sczhyt.common.utils.PageUtils;
import cn.sczhyt.common.utils.R;


/**
 * @author luoshijie
 * @email 1169414426@qq.com
 * @date 2020-11-25 10:54:22
 */
@Api(tags = "APP会议签到")
@RestController
@RequestMapping("app/meetingsignin")
public class AppMeetingSignInController {
    @Autowired
    private MeetingSignInService meetingSignInService;

    @Autowired
    private MeetingService meetingService;

    /**
     * 会议签到功能
     */
    @Login
    @ApiOperation("会议签到功能")
    @PostMapping("signin/{meetingId}")
    public R signIn(@LoginUser UserEntity user,
                    @PathVariable("meetingId") String meetingId,@RequestParam String signAddress) {

        String userId = user.getUserId();
        String username = user.getUsername();

        return meetingSignInService.signIn(userId, username, meetingId,signAddress);

    }

    /**
     * 查询自己是否会议签到
     */
    @Login
    @ApiOperation("查询自己是否会议签到")
    @GetMapping("check/{meetingId}")
    public boolean check(@LoginUser UserEntity user,
                         @PathVariable("meetingId") String meetingId) {

        String userId = user.getUserId();
        String username = user.getUsername();

        return meetingSignInService.check(userId, username, meetingId);

    }


    /**
     * 会议签到列表
     */
    @Login
    @ApiOperation("会议签到列表")
    @GetMapping("/list")
    public R list(@RequestParam String meetingId,
                  @RequestParam(defaultValue = "1") Integer page,
                  @RequestParam(defaultValue = "1000") Integer limit) {

        IPage<MeetingSignInEntity> iPage = meetingSignInService.listByMeetingId(meetingId, page, limit);

        PageUtils list = new PageUtils(iPage);

        return R.ok().put("data", list);
    }


    /**
     * 会议未签到列表
     */
    @ApiOperation("PC查看会议签到列表")
    @RequestMapping("/list/notsignin")
    public R listNotSignIn(@RequestParam String meetingId,
                           @RequestParam(defaultValue = "1") Integer page,
                           @RequestParam(defaultValue = "1000") Integer limit) {

        IPage<MeetingUserEntity> iPage = meetingSignInService.listNotSignInByMeetingId(meetingId, page, limit);

        PageUtils list = new PageUtils(iPage);

        return R.ok().put("page", list);
    }


}
